package com.study.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisUtil {

	private static final String host = "192.168.150.129";
	
	private static final int port = 6379;
	
	private static final String password = "1234";
	
	private static JedisPool jedisPool;
	
	
	public static Jedis getJedis() {
        
		JedisPoolConfig config = new JedisPoolConfig(); 
        config.setMaxTotal(20); 
        config.setMaxIdle(5); 
        config.setTestOnBorrow(false); 
        
		jedisPool = new JedisPool(config,host, port,3000,password);
		Jedis jedis = jedisPool.getResource(); 
		String code = jedis.auth(password); //如果没有配置密码验证，这注掉这句话
		//System.out.println("auth code :" + code);
		//jedis.select(1);//选择第二个数据库演示
		return jedis;
	}
	
	
	/*public static Jedis getJedis(int index) {
        
        
		jedisPool = new JedisPool(config,host, port,3000,password);
		Jedis jedis = jedisPool.getResource(); 
		
		String code = jedis.auth(password); //如果没有配置密码验证，这注掉这句话
		System.out.println("auth code :" + code);
		jedis.select(index);//选择第二个数据库演示
		return jedis;
	}*/
	
	
	public static void main(String[] args) {
		Jedis jedis = getJedis();
		jedis.close();
	}
	
}
